<#include "/macro.include"/>
<#include "/java_copyright.include">
<#assign className = table.className>   
<#assign classNameLower = className?uncap_first> 
package ${basepackage}.${namespace}.bo;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Service;
import com.itcmor.platform.base.bo.BaseBOImpl;
import com.itcmor.platform.base.common.OrderProperty;
import com.itcmor.platform.base.common.SearchCondition;
import com.itcmor.platform.base.exception.ItcmorException;
import org.apache.commons.lang3.StringUtils;
import com.itcmor.platform.base.page.PageInfo;
import ${basepackage}.${namespace}.vo.${className};
@Service("${classNameLower}BO")
public class ${className}BOImpl extends BaseBOImpl<${className}> implements ${className}BO  {
	private static final long serialVersionUID = 1L;
	@Override
	public List<${className}> list(${className} ${classNameLower},List<OrderProperty>  ops, PageInfo pageInfo ) throws ItcmorException {
		 if(ops == null)
		    	ops = new ArrayList<OrderProperty>();
		    List<SearchCondition> scs  = this.initScs(${classNameLower}); 
	    try{
	    	List<${className}> list =  this.list(${classNameLower}, scs, ops,pageInfo);
		return list;
	    }catch (Exception e) {
	    	e.printStackTrace();
	    	throw new ItcmorException();
		}
	}
	@Override
	public int count(${className} ${classNameLower}) throws ItcmorException {
		 List<SearchCondition> scs  = this.initScs(${classNameLower}); 
		 return this.count(${classNameLower}, scs);
	}
	@Override
	public List<${className}> list(${className} ${classNameLower}, List<OrderProperty> ops)throws ItcmorException {
		if(ops == null)
	    	ops = new ArrayList<OrderProperty>();
	    List<SearchCondition> scs  = this.initScs(${classNameLower}); 
	    
	    try{
	    	List<${className}> list = this.list(${classNameLower}, scs, ops);
		return list;
	    }catch (Exception e) {
	    	e.printStackTrace();
	    	throw new ItcmorException();
		}
	}
	@Override
	public List<SearchCondition> initScs(${className} ${classNameLower}) {
		 List<SearchCondition> scs = new ArrayList<SearchCondition>();
		    if(${classNameLower}!=null){
		              <@generateNotPkProperties/>  
				             <#macro generateNotPkProperties>
												<#list table.columns as column>
													 <#if !column.pk>
								if(!StringUtils.isEmpty(${classNameLower}.get${column.columnName}())){ 
													         <#if column.isDateTimeColumn>  
								scs.add(SearchCondition.ge("${column.columnName}",${classNameLower}.get${column.columnName}()));
		            									 <#else> 
								scs.add(SearchCondition.like("${column.columnName}",${classNameLower}.get${column.columnName}()));
		            								   </#if>
		                             } 
													</#if>
	                        </#list>
	                        <#list table.columns as column>
													 <#if column.pk>
								if(!StringUtils.isEmpty(${classNameLower}.get${column.columnName}())){ 
								scs.add(SearchCondition.eq("${column.columnName}",${classNameLower}.get${column.columnName}()));
									               }
													</#if>
	                        </#list>
	                        </#macro>
		             
		    } 
		return scs;
	}
}